package edu.stonybrook.cs.gars.client;

import java.io.Serializable;

import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.TextBox;

public class ApplicationTable extends FlexTable
{
	private static FlexTable applicationTableInstance = null;
	
	private Timer t;
	
	private ApplicationTable()
	{
		super();
		
		TextBox textBox = null;
				
		for(int row = 0; row < 100; row ++)
		{
			for(int column = 0; column < 50; column ++)
			{
				textBox = new TextBox();
				textBox.setText("testData");
				this.setWidget(row, column, textBox);
			}
		}
		
		t = new Timer() 
		{
		      public void run() 
		      {
					TextBox textBox = new TextBox();
					textBox.setText("dynamicAdd");
					int randomRow = Random.nextInt(100);
					int randomColumn = Random.nextInt(50);
					ApplicationTable.this.insertCell(randomRow, randomColumn);
					ApplicationTable.this.setWidget(randomRow, randomColumn, textBox);
		      }
		};
		
		//t.scheduleRepeating(5000);
	}
	
	
	
	public static void createApplicationTableInstanceIfNull()
	{
		if(applicationTableInstance == null)
			applicationTableInstance = new ApplicationTable();
	}
	
	public static void destroyApplicationTableInstance()
	{
		applicationTableInstance = null;
	}
	
	public static void replaceApplicationTableInstance()
	{
		applicationTableInstance = new ApplicationTable();
	}
	
	
	public static FlexTable getApplicationTableInstance()
	{
		createApplicationTableInstanceIfNull();
		
		return applicationTableInstance;
	}
	
}